#ifndef CPP_IPC_H
#define CPP_IPC_H

#include <pthread.h>
#include <cvte_message.h>
#include <cvte_system_guard.h>

//@brief 进程间通信（Inter-Process Communication）
//@author cvte
//@description 进程间通信（Inter
class IPC {
   public:
    class IPCListener {
       public:
        virtual void onIPCReceiveData(CVTE_MESSAGE_DATA* data);
        virtual void onIPCReceiveLongData(CVTE_MESSAGE_DATA_JSON* data);
    };

    static IPC* getInstance();
    //@method 发送其他进程消息
    static void sendWithId(CVTE_ID_APP id_reciver, CVTE_TYPE_NOTIFY type, int id_notify, uint8_t* data, uint32_t data_len);
    void setListener(IPCListener& listener);

   private:
    static IPC* sInstance;
    static int mId;
    static CVTE_MESSAGE_DATA mDataRecv;
    static CVTE_MESSAGE_DATA_JSON mDataRecvJson;
    static IPCListener* mListener;
    pthread_t mPthreadRecv;

    IPC();
    ~IPC();

    //@method 接收线程
    static void* recvThreadProc(void* arg);
    //@method 消息队列清理
    static void messageQueueClean(void);
};

#endif